// pages/loading.js
var util = require('../utils/util.js');
var qcloud = require('../vendor/wafer2-client-sdk/index');
var config = require('../config');
var app = getApp();
Page({
  data: {
    loading: true,
  },
  onLoad: function () {
    var that = this;
    app.getUserInfo(function () {
      app.toIndex()//加载成功
    }, function () {
      
      that.setData({ loading: false })//加载失败
    });
  },
  login: function (e) {
    app.globalData.userInfo = e.detail.userInfo;
    console.log('用户信息', app.globalData.userInfo);
    wx.login({
      success: function (res) {
        var code = res.code;
        app.login(code, e.detail, function () {
          app.toIndex()
        });
      }
    })
  },
  
  //跳转设置页面授权
  openSetting: function () {
    var that = this
    if (wx.openSetting) {
      wx.openSetting({
        success: function (res) {
          //尝试再次登录
          that.login()
        }
      })
    } else {
      wx.showModal({
        title: '授权提示',
        content: '小程序需要您的微信授权才能使用哦~ 错过授权页面的处理方法：删除小程序->重新搜索进入->点击授权按钮'
      })
    }
  }
 
})